package com.jsmy.softapp.presenter;

import com.jsmy.softapp.MyApp;
import com.jsmy.softapp.model.DataModel;
import com.jsmy.softapp.net.API;
import com.jsmy.softapp.util.SPF;
import com.jsmy.softapp.util.ToastUtil;
import com.jsmy.softapp.view.DataView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created with Android Studio.
 * User: wei_cd.
 * Date: 2018/4/19.
 * Time: 11:35.
 * To change for file | settings | file and code templates.
 */

public class DataPresenter extends BasePresenter<DataView> {
    public DataModel model = new DataModel();

    public void getappsyzlgdlist(String groupcd, int pageindex) {
        if (model != null && getView() != null) {
            getView().showLoading();
            Map<String, String> map = new HashMap<>();
            map.put("lid", SPF.getString(MyApp.getMyApp(), SPF.SP_ZH, MyApp.getMyApp().bean.getUsername()));
            map.put("groupcd", groupcd);
            map.put("pageindex", "" + pageindex);
            model.loadData(API.APP_ZL_GD_LIST, map, this);
        }
    }

    public void getappzlgrouplist(){
        if (model != null && getView() != null) {
            getView().showLoading();
            Map<String, String> map = new HashMap<>();
            map.put("lid", SPF.getString(MyApp.getMyApp(), SPF.SP_ZH, MyApp.getMyApp().bean.getUsername()));
            model.loadData(API.APP_ZL_GROUP_LIST, map, this);
        }
    }

    public void savefxinfo(String id, String planid, String pt, String obj) {
        if (model != null && getView() != null) {
            getView().showLoading();
            Map<String, String> map = new HashMap<>();
            map.put("lid", SPF.getString(MyApp.getMyApp(), SPF.SP_ZH, MyApp.getMyApp().bean.getUsername()));
            map.put("id", id);
            map.put("planid", planid);
            map.put("pt", pt);
            map.put("obj", obj);
            model.loadData(API.APP_SAVE_FX_INFO, map, this);
        }
    }

    @Override
    public void onComplete(String type, String code, String msg, Object object) {
        if (getView() != null) {
            switch (code) {
                case "N":
//                    break;
                case "Y":
                    getView().showLoadingData(type, object);
                    break;
                default:
                    ToastUtil.showShort(MyApp.getMyApp(), msg);
                    break;
            }
            getView().hideLoading();
        }
    }
}
